package com.baizan.daka.ui.presenter

import com.baizan.daka.base.BasePresenter
import com.baizan.daka.ui.contract.HomeFrgContract
import com.baizan.daka.mvp.model.BannerModel
import com.baizan.daka.mvp.model.NewsModel
import com.baizan.daka.mvp.model.TaskModel
import com.baizan.daka.mvp.model.bean.BannerBean
import com.baizan.daka.mvp.model.bean.NewsInfoBean
import com.baizan.daka.mvp.model.bean.TaskInfoBean
import com.baizan.daka.net.BasePageResponse
import com.baizan.daka.rx.Subscriber.CommonSubscriber
import com.baizan.daka.showToast
import com.baizan.daka.ui.contract.TaskHomeContract

class TaskHomePresenter(val mView: TaskHomeContract.View) : BasePresenter(),
    TaskHomeContract.Presenter {

    val taskModel: TaskModel by lazy { TaskModel() }

    override fun loadList(CurrentPage: Int,level: Int? ,taskClass:Int? ) {
        mView.showLoadingDialog()
        taskModel.list(CurrentPage,level,taskClass)
            .subscribe(object :
                CommonSubscriber<BasePageResponse<TaskInfoBean>>(compositeDisposable) {

                override fun onCallNext(t: BasePageResponse<TaskInfoBean>?) {
                    mView.loadListSuccess(t!!)
                }

                override fun onCallError(e: String) {
                    super.onCallError(e)
                    showToast(e)
                }

                override fun onCallCompleted() {
                    super.onCallCompleted()
                    mView.hideLoadingDialog()
                }
            })

    }
    override fun receiveTask(index:Int,taskId: Long) {
        mView.showLoadingDialog()
        taskModel.receivedTask(taskId)
            .subscribe(object :
                CommonSubscriber<Any>(compositeDisposable) {

                override fun onCallNext(t: Any?) {
                    mView.receiveTaskSuccess(index,t!!)
                }

                override fun onCallError(e: String) {
                    super.onCallError(e)
                    showToast(e)
                }

                override fun onCallCompleted() {
                    super.onCallCompleted()
                    mView.hideLoadingDialog()
                }
            })
    }

}

